using AnalyStock.DataManage;

namespace AnalyStock.GrapImage;

/// <summary>
///     追加股票分类概念面板
/// </summary>
public partial class ChartKline : UserControl
{
    private void InitializeMenu_ConceptionClassify()
    {
        ConceptionClassifyPanel.Visibility = Visibility.Hidden;
        BtnAddCalssify.Click += UpdateClassify_Clicked;
        BtnCancelCalssify.Click += (s, e) => HiddenClassifyPanel();
        ConceptionClassifyPanel.InitializeMouseDarg(this);
    }

    private async void UpdateClassify_Clicked(object sender, RoutedEventArgs e)
    {
        if (!string.IsNullOrEmpty(TextBoxConception.Text))
        {
            var _conceptionName = TextBoxConception.Text.Trim();
            var _conceptionOrderID = TextBoxConceptionOrderID.Text.Trim();
            var _conceptions = new List<Conception>
            {
                new($"{_conceptionName}01", _conceptionName, _conceptionOrderID)
            };
            var _result = await CommDataMethod<Conception>
                .SaveConceptionClassifyAsync(_conceptions, $"{_conceptionName}01");
            if (_result > 0)
            {
                MenuItem menuItem_AddConception = new()
                {
                    Header = _conceptionName,
                    ToolTip = _conceptionOrderID,
                    Name = "Add",
                    Style = SetElementStyle("MenuItemStyle")
                };
                menuItem_AddConception.Click += UpdateSeleStock;
                (ContextMenu.Items[0] as MenuItem).Items.Add(menuItem_AddConception);
            }
        }
        HiddenClassifyPanel();
    }

    private void HiddenClassifyPanel()
    {
        TextBoxConception.Clear();
        ConceptionClassifyPanel.Visibility = Visibility.Hidden;
    }
}